from django.http import JsonResponse
from django.shortcuts import render
from ad_manage.models import Advertisement
from adlist.controller import get_data_controller

from django.views.decorators.csrf import csrf_exempt

from utils.request_decorator import getData_api_auth


@csrf_exempt
@getData_api_auth
def getData(request):

    page = int(request.GET.get('page'))
    pageSize = int(request.GET.get('pageSize'))
    advertisement = Advertisement.objects.all().exclude(logo='暂无').exclude(local_img='暂无').exclude(local_img='')
    token = request.COOKIES.get('tooken', '')
    public_time = request.GET.get('public_time')
    discover_time = request.GET.get('discover_time')
    search_text = request.GET.get('search_text')
    app_from = request.GET.get('app_from')
    advertisements = get_data_controller(page, pageSize, token, advertisement, public_time, discover_time, search_text,
                                         app_from)
    return JsonResponse(advertisements)


def searchAd(request):
    return None


@csrf_exempt
def index(request):
    return render(request, 'html/main/index.html', None)


def index2(request):
    return render(request, 'html/main/index_test.html', None)


@csrf_exempt
def index_details(request):
    return render(request, 'html/main/index_details.html', None)


def agreement_page(request):
    return render(request, 'html/main/agreement.html', None)


def privacy(request):
    return render(request, 'html/main/privacy.html', None)


def index_test(request):
    return render(request, 'html/main/index_test.html', None)


@csrf_exempt
def test_detail(request):
    return render(request, 'html/main/index_details2.html', None)
